@using BlazorApp.Pages.Common
@using BlazorApp.Pages.Common.Html
@using BlazorApp.Pages.Common.Html.HTable
@using BlazorApp.Pages.Common.Metadata
@using Extension
@using k8s.Models
@inherits BlazorApp.Pages.Common.DrawerPageBase<V1PodSecurityContext>
@if (PodSecurityContext != null && !PodSecurityContext.ToJson().Equals("{}"))
{
    <Divider Orientation="left" Style="font-weight:bold"> PodSecurityContext </Divider>

    <HTable Bordered Column="1">
        <PropertySimpleView Title=@L["FsGroup"] Item="@PodSecurityContext.FsGroup"
                            ExplainField="pod.spec.securityContext.fsGroup">
        </PropertySimpleView>
        <PropertyOptionView Title=@L["FsGroupChangePolicy"] ExplainField="pod.spec.securityContext.fsGroupChangePolicy"
                            Item="@PodSecurityContext.FsGroupChangePolicy"
                            Options='@(new[] { "OnRootMismatch", "Always" })'>
        </PropertyOptionView>
        <PropertySimpleView Title=@L["RunAsGroup"] Item="@PodSecurityContext.RunAsGroup"
                            ExplainField="pod.spec.securityContext.runAsGroup">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["RunAsNonRoot"] Item="@PodSecurityContext.RunAsNonRoot"
                            ExplainField="pod.spec.securityContext.runAsNonRoot">
        </PropertySimpleView>
        <PropertySimpleView Title=@L["RunAsUser"] Item="@PodSecurityContext.RunAsUser"
                            ExplainField="pod.spec.securityContext.runAsUser">
        </PropertySimpleView>

        @if (PodSecurityContext.SeLinuxOptions != null)
        {
            <HTableColumn Title=@L["SeLinuxOptions"] ExplainField="pod.spec.securityContext.seLinuxOptions">

                @if (PodSecurityContext.SeLinuxOptions.Level != null)
                {
                    <ColorfulTag >
                        @($"Level={PodSecurityContext.SeLinuxOptions.Level}")
                    </ColorfulTag>
                }
                @if (PodSecurityContext.SeLinuxOptions.User != null)
                {
                    <ColorfulTag >
                        @($"User={PodSecurityContext.SeLinuxOptions.User}")
                    </ColorfulTag>
                }
                @if (PodSecurityContext.SeLinuxOptions.Type != null)
                {
                    <ColorfulTag >
                        @($"Type={PodSecurityContext.SeLinuxOptions.Type}")
                    </ColorfulTag>
                }
                @if (PodSecurityContext.SeLinuxOptions.Role != null)
                {
                    <ColorfulTag >
                        @($"Role={PodSecurityContext.SeLinuxOptions.Role}")
                    </ColorfulTag>
                }
            </HTableColumn>
        }
        @if (PodSecurityContext.SeccompProfile != null)
        {
            <PropertyOptionView Title=@L["SeccompProfile"] ExplainField="pod.spec.securityContext.seccompProfile"
                                Item="@PodSecurityContext.SeccompProfile.Type"
                                Options='@(new[] { "Localhost", "RuntimeDefault", "Unconfined" })'>
            </PropertyOptionView>
            <PropertySimpleView Title=@L["LocalhostProfile"]
                                ExplainField="pod.spec.securityContext.seccompProfile.LocalhostProfile"
                                Item="@PodSecurityContext.SeccompProfile.LocalhostProfile">
            </PropertySimpleView>
        }
        <PropertyListView Title=@L["SupplementalGroups"] ExplainField="pod.spec.securityContext.supplementalGroups"
                          Items="@PodSecurityContext.SupplementalGroups" T="long?">
        </PropertyListView>

        @if (PodSecurityContext.Sysctls != null)
        {
            <HTableColumn Title=@L["Sysctls"] ExplainField="pod.spec.securityContext.sysctls">

                @foreach (var sysctl in PodSecurityContext.Sysctls)
                {
                    <div>
                        <ColorfulTag >
                            @($"{sysctl.Name}={sysctl.Value}")
                        </ColorfulTag>
                    </div>
                }

            </HTableColumn>
        }

        @if (PodSecurityContext.WindowsOptions != null)
        {
            <HTableColumn Title=@L["WindowsOptions"] ExplainField="pod.spec.securityContext.windowsOptions">


                @if (PodSecurityContext.WindowsOptions.GmsaCredentialSpec != null)
                {
                    <div>
                        <ColorfulTag >
                            @($"GmsaCredentialSpec={PodSecurityContext.WindowsOptions.GmsaCredentialSpec}")
                        </ColorfulTag>
                    </div>
                }
                @if (PodSecurityContext.WindowsOptions.GmsaCredentialSpecName != null)
                {
                    <div>
                        <ColorfulTag >
                            @($"GmsaCredentialSpecName={PodSecurityContext.WindowsOptions.GmsaCredentialSpecName}")
                        </ColorfulTag>
                    </div>
                }
                @if (PodSecurityContext.WindowsOptions.HostProcess != null)
                {
                    <div>
                        <ColorfulTag >
                            @($"HostProcess={PodSecurityContext.WindowsOptions.HostProcess}")
                        </ColorfulTag>
                    </div>
                }
                @if (PodSecurityContext.WindowsOptions.RunAsUserName != null)
                {
                    <div>
                        <ColorfulTag >
                            @($"RunAsUserName={PodSecurityContext.WindowsOptions.RunAsUserName}")
                        </ColorfulTag>
                    </div>
                }
            </HTableColumn>
        }
    </HTable>
}

@code{

    [Parameter] public V1PodSecurityContext PodSecurityContext { get; set; }

}
